//
//  MainTabBarController.m
//  ShoppingCenter
//
//  Created by renyong on 16/3/8.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "MainTabBarController.h"

@interface MainTabBarController ()
@property (nonatomic, strong) NSMutableArray * viewControllersArr;/**< 标签控制器数组 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeAppearance;/**< 一般界面初始化 */


@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeAppearance];
    for (UITabBarItem * item in self.tabBar.items) {
        item.imageInsets = UIEdgeInsetsMake(-2, 0, 2, 0);
    }
    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_RGB(108, 108, 108, 1), NSForegroundColorAttributeName, [UIFont systemFontOfSize:9*DHFlexibleHorizontalMutiplier()], NSFontAttributeName,nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_RGB(237, 46, 46, 1), NSForegroundColorAttributeName, [UIFont systemFontOfSize:9*DHFlexibleHorizontalMutiplier()], NSFontAttributeName,nil] forState:UIControlStateSelected];
    
}

- (BOOL)shouldAutorotate {
    return NO;
}
#pragma mark - init
- (void)initializeDataSource {
    self.viewControllersArr = [NSMutableArray arrayWithCapacity:0];
    NSArray * controllersTitles = @[@"WPHomePageViewController", @"WPKindsViewController", @"WPForumViewController", @"WPUserInfoViewController"];
    NSArray * VCtitles = @[@"首页", @"分类", @"论坛", @"个人中心"];
    NSArray * vcImages = @[@"首页默认.png", @"分类默认.png", @"论坛默认.png", @"个人中心默认-0.png"];
    NSArray * vcSelectedImages = @[@"首页选中.png", @"分类选中.png", @"论坛选中.png", @"个人中心选中.png"];
    for (int i = 0; i < vcImages.count; i++) {
        UIViewController * vc = [[NSClassFromString(controllersTitles[i])alloc]init];
        UINavigationController * navvc = [self navigationControllerWithRootVC:vc title:VCtitles[i] imgName:vcImages[i] selectImgName:vcSelectedImages[i]];
        [_viewControllersArr addObject:navvc];
    }
}

- (void) initializeAppearance {
    self.tabBar.tintColor = tabBarColor;
    self.viewControllers  = [NSArray arrayWithArray:self.viewControllersArr];
}

- (UINavigationController *) navigationControllerWithRootVC:(UIViewController *) vC title:(NSString *) title imgName:(NSString *) img selectImgName:(NSString *) selImg {
    vC.tabBarItem.title         = title;
    vC.tabBarItem.image         = [UIImage imageNamed:img];
    vC.tabBarItem.selectedImage = [UIImage imageNamed:selImg];
    UINavigationController * navvc = [[UINavigationController alloc]initWithRootViewController:vC];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    navvc.interactivePopGestureRecognizer.enabled = YES;
    return navvc;
}

@end
